package merge_sort;
/**
 * @Author: sfy
 * @Date: 2024/1/25 19:29
 * @Description: 逆序对的数量
 */
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args)  {
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i<n;i++){
            arr[i] = scanner.nextInt();
        }
        long res = mergeSort(arr, 0, n - 1);
        System.out.println(res);
    }

    private static long mergeSort(int[] arr, int l, int r) {
        if (l>=r) return 0;

        int mid = l+r>>1;
        long res = mergeSort(arr,l,mid)+mergeSort(arr,mid+1,r);
        int[] temp = new int[r-l+1];
        int i = l,j = mid+1,k=0;
        while(i<=mid && j<=r){
            if(arr[i]<=arr[j]){
                temp[k++] = arr[i++];
            }else{
                res += mid-i+1;
                temp[k++] = arr[j++];
            }
        }
        while (i <= mid)  temp[k++] = arr[i++];
        while (j <= r)   temp[k++] = arr[j++];
        for(i=l,j=0;i<=r;i++,j++)arr[i]=temp[j];
        return res;
    }
}

